/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package base;

import xmlparser.bugParser;

/**
 *
 * @author pbelov
 */

public class Bug {

    // all items are publiс are temporary.
    private int ID;

    private String title;
    private String description;

    private String project;
    private String device;

    private String assignee;
    private String creator;
    private String tester;

    private String bugVer;
    private String fixVer;

    private int fixNumber;
    private int priority; //1-5
    private int state;

    static int priorityCount = 5;
    static int stateCount = 8;
            
    public static int counter = 0;

    private int commentsCount = 0;
    private String comment[];

    public Bug() {
        comment = new String[1];
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setDevice(String device) {
        this.device = device;
    }

    public void setProject(String project) {
        this.project = project;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public void setAssignee(String assignee) {
        this.assignee = assignee;
    }

    public void setTester(String tester) {
        this.tester = tester;
    }

    public void setBugVer(String bugVer) {
        this.bugVer = bugVer;
    }

    public void setFixVer(String fixVer) {
        this.fixVer = fixVer;
    }

    public void setFixNumber(int fixNumber) {
        this.fixNumber = fixNumber;
    }

    public void setPriority(int priority) {
        if (priority > 0 && priority < priorityCount) {
            this.priority = priority;
        } else {
            this.priority = -1; // invalid priority
        }
    }

    public void setState(int state) {
        if (state > 0 && state < stateCount) {
            this.state = state;
        } else {
            this.state = -1; //invalid state
        }
    }

   public int getID() {
        return ID;
    }

    public String getTitle() {
        return title;
    }

    public String getDescription() {
        return description;
    }

    public String getDevice() {
        return device;
    }

    public String getProject() {
        return project;
    }

    public String getCreator() {
        return creator;
    }

    public String getAssignee() {
        return assignee;
    }

    public String getTester() {
        return tester;
    }

    public String getBugVer() {
        return bugVer;
    }

    public String getFixVer() {
        return fixVer;
    }

    public int getFixNumber() {
        return fixNumber;
    }

    public int getPriority() {
        return priority;
    }

    public int getState() {
        return state;
    }

    public void setCommentsCount(int n) {
        commentsCount = n;
    }

    public int incCommentCount() {
        commentsCount++;
        return commentsCount;
    }

    public int getCommentsCount() {
        return comment.length;
    }

    public String getComment(int i) {
        String res = null;
        if (i >= 0 && i < comment.length) {
            res = comment[i];
        }
        return res;
    }

    public void addComment(String com) {
        String commCopy[] = new String[commentsCount];
        for (int i = 0; i < commentsCount; i++) {
            commCopy[i] = new String(comment[i]);
        }
        System.out.println("[DBG] Adding [" + commentsCount + "] comment: " + com);
        incCommentCount();
        comment = new String[commentsCount];
        for (int i = 0; i < commentsCount - 1; i++) {
            comment[i] = new String(commCopy[i]);
        }
        comment[commentsCount - 1] = new String(com);
    }

    public void createTestBug(int id) {
        setID(id);
        setTitle(bugParser.TITLE + "_" + Integer.toString(id));
        setDescription(bugParser.DESC + "_" + Integer.toString(id));
        setAssignee(bugParser.ASSIGNEE + "_" + Integer.toString(id));
        setCreator(bugParser.CREATOR + "_" + Integer.toString(id));
        setTester(bugParser.TESTER + "_" + Integer.toString(id));
        setDevice(bugParser.DEVICE + "_" + Integer.toString(id));
        setProject(bugParser.PROJECT + "_" + Integer.toString(id));
        setPriority(3);
        setState(3);
        setBugVer(bugParser.BUGVER + "_" + Integer.toString(id));
        setFixVer(bugParser.FIXVER + "_" + Integer.toString(id));
        setFixNumber(3);
        addComment(bugParser.COMMENT + "_" + 1);
        addComment(bugParser.COMMENT + "_" + 2);
        addComment(bugParser.COMMENT + "_" + 3);
    }
}